package com.pfizer.Entity;

import java.util.ArrayList;

/**
 * Question--<b>問卷問題信息實體</b>--靜態變量為創建數據庫表需要的字段名
 * 
 * @author krui
 * @version 1.40 2011/11/19
 */
import java.util.Iterator;
import java.util.List;

import com.pfizer.Public.PublicFunc;

public class Question {

	public static final String QUESTIONSTRING = "Question";
	public static final String QUESTIONNAIREIDSTRING = "Questionnaire_ID";
	public static final String QUESTIONIDSTRING = "Question_ID";
	public static final String QUESTIONNOSTRING = "Question_No";
	public static final String QUESTIONSUBJSTRING = "Question_Subj";
	public static final String ANSWERTYPESTRING = "Answer_Type";
	public static final String OPTIONCNTSTRING = "Option_Cnt";
	public static final String MINSELECTCNTSTRING = "Min_Select_Cnt";
	public static final String MAXSELECTCNTSTRING = "Max_Select_Cnt";
	public static final String OPTIONSTRING = "Option";

	private long Questionnaire_ID = 0;
	private long Question_ID = 0;
	private int Question_No = 0;
	private String Question_Subj = "";
	private String Answer_Type = "";
	private int Option_Cnt;
	private int Min_Select_Cnt;
	private int Max_Select_Cnt;
	private String Options_String;
	private List<QuestionOption> qOptions;
	private int 	UserSelectedOptionID=-1;
	public Question(long _ID) {
		this.Question_ID = _ID;
	}

	public Question() {
		qOptions = new ArrayList<QuestionOption>();
	}

	public void setQuestionnaireID(long _ID) {
		this.Questionnaire_ID = _ID;
	}

	public long getQuestionnaireID() {
		return this.Questionnaire_ID;
	}

	public void setID(String _ID) {
		this.Question_ID = new Long(_ID).intValue();
	}

	public void setID(long _ID) {
		this.Question_ID = _ID;
	}

	public long getID() {
		return this.Question_ID;
	}

	public void setNo(String _No) {
		this.Question_No = new Integer(_No).intValue();
	}

	public void setNo(int _No) {
		this.Question_No = _No;
	}

	public int getNo() {
		return this.Question_No;
	}

	public void setSubj(String _Subj) {
		this.Question_Subj = _Subj;
	}

	public String getSubj() {
		return this.Question_Subj;
	}

	public void setAnswerType(String _AnswerType) {
		this.Answer_Type = _AnswerType;
	}

	public String getAnswerType() {
		return this.Answer_Type;
	}

	public void setOptionCnt(String _OptionCnt) {
		this.Option_Cnt = new Integer(_OptionCnt).intValue();
	}

	public void setOptionCnt(int _OptionCnt) {
		this.Option_Cnt = _OptionCnt;
	}

	public int getOptionCnt() {
		return this.Option_Cnt;
	}

	public void setMaxSelectCnt(String _MaxSelectCnt) {
		this.Max_Select_Cnt = new Integer(_MaxSelectCnt).intValue();
	}

	public void setMaxSelectCnt(int _MaxSelectCnt) {
		this.Max_Select_Cnt = _MaxSelectCnt;
	}

	public int getMaxSelectCnt() {
		return this.Max_Select_Cnt;
	}

	public void setMinSelectCnt(String _MinSelectCnt) {
		this.Min_Select_Cnt = new Integer(_MinSelectCnt).intValue();
	}

	public void setMinSelectCnt(int _MinSelectCnt) {
		this.Min_Select_Cnt = _MinSelectCnt;
	}

	public int getMinSelectCnt() {
		return this.Min_Select_Cnt;
	}

	public void setOption(QuestionOption qOption) {
		qOptions.add(qOption);
	}

	public void setOption(String qoString) {
		if (qoString.length() > 0) {
			String[] aOpt = PublicFunc.split(qoString, "|%|");
			String[] aTmp;
			int ilen = aOpt.length;
			for (int i = 0; i < ilen; i++) {
				QuestionOption qOption = new QuestionOption();
				aTmp = PublicFunc.split(aOpt[i], "|*|");
				qOption.setID(aTmp[0]);
				qOption.setDesc(aTmp[1]);
				qOption.setIsCorrect(aTmp[2]);
				qOptions.add(qOption);
			}
		}
		
	}
	public void setUserSctOptID(int _oID)
	{
		this.UserSelectedOptionID=_oID;
	}
	public int getUserSctOptID()
	{
		return this.UserSelectedOptionID;
	}
	public List<QuestionOption> getOptions() {
		return this.qOptions;
	}

	public void setOptionString(String _optionString) {
		this.Options_String = _optionString;
	}

	@SuppressWarnings("unchecked")
	public void setOptionString() {
		Options_String = "";
		for (Iterator iterator = qOptions.iterator(); iterator.hasNext();) {
			QuestionOption qOption = (QuestionOption) iterator.next();
			Options_String += qOption.toString() + "|%|";
		}
		if (Options_String.length() > 0) {
			Options_String = Options_String.substring(0, Options_String
					.length() - 3);
		}
	}

	

	public String getOptionString() {
		return this.Options_String;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return String.valueOf(this.Question_ID) + ",name  "
				+ this.Question_Subj + "\n";
	}
}
